<?php 

session_start();
$dbconnect = pg_connect('host=dbsrv1 dbname=csc309g7 user=csc309g7 password=aiboid4p') || die();

$id = $_SESSION['userid'];

	$getPlayerRating_query = "select ppl.userid userid,  ppl.username username, (ratings.likes + ratings.dislikes) total_votes, 
								to_char(ratings.likes::double precision/ (ratings.likes + ratings.dislikes) *100,'999.9') || '% ' rating from 
								people ppl inner join ratings ratings on ratings.userid = ppl.userid where ppl.userid =$id and ratings.likes + ratings.dislikes <> 0 ";
	
	$getPlayerRating_result = pg_query($getPlayerRating_query);
	
	$test = pg_num_rows($getPlayerRating_result);
		
	if ($test != 0) {
			
		while($results = pg_fetch_assoc($getPlayerRating_result))
		{
			echo "Total votes: ".$results['total_votes'] . "     Rating: ". $results['rating'];
		} 
			
	} else {
		echo "This player have no been rated yet";
	}	


?>

